package com.hxunicorn.btc.api.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 应用模块名<br>
 * <p>
 * 代码描述
 * <p>
 * Copyright: Copyright (C) 2020, Inc. All rights reserved. <br>
 * Company: 寰星网络<br>
 *
 * @author Levin
 * @since 2020/4/13 10:36
 */
@EnableSwagger2
@Configuration
public class SwaggerConfig{

    /**
     * api接口包扫描路径
     */
    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.hxunicorn";

    /**
     * api版本号
     */
    public static final String VERSION = "0.0.1";

    @Bean
    public Docket controllerApi() {
        // 添加head参数start
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        tokenPar.name("Auth-Code").description("头部令牌码").modelRef(new ModelRef("string")).parameterType("header")
            .required(false).build();
        pars.add((Parameter)tokenPar.build());
        // 添加head参数end
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
            .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE)).paths(PathSelectors.any()).build()
            .globalOperationParameters(pars);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("寰星网络-B2C电商平台").description("API 接口文档").version(VERSION).build();
    }
}
